package com.gmail.ceac13;

import java.util.List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ListView;

public class RequisicoesActivity extends Activity {
	List<Friend> list;
	ListView lista;
	SharedPreferences settings;

	protected static final int ATUALIZAR_LISTA = 1;
	private Handler handler = new RequisicoesHandler();
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.requisicoes);
	}
	public void onStart() {
		super.onStart();
		
        Message msg = new Message();
        msg.what = ATUALIZAR_LISTA;
        handler.sendMessage(msg);
	}
	public void carregarLista() {
		settings = getSharedPreferences("ConnectMe",MODE_PRIVATE);
        int user_id = settings.getInt("user_id", -1);
        
  	  	String endServer = settings.getString("servidor", "http://connectme.scienceontheweb.net/");
  	  	//String endServer = settings.getString("servidor", "http://10.0.2.2/connectme/");
		list = Servidor.listarRequisicoes(user_id, endServer);
	}
	private class RequisicoesHandler extends Handler {
		public void handleMessage(Message msg) {
			switch(msg.what) {
			case ATUALIZAR_LISTA:
				lista = (ListView)findViewById(R.id.listaRequisicoes);        
		        settings = getSharedPreferences("ConnectMe",MODE_PRIVATE);
				carregarLista();
				RequisicoesAdapter adapter;
		        int user_id = settings.getInt("user_id", -1);
				adapter = new RequisicoesAdapter(RequisicoesActivity.this, list, user_id);
				lista.setAdapter(adapter);
				ConnectMEActivity.dialog.dismiss();
				break;
			}
		}
	}
}
